package com.hc.acoustics.ui.activity

import android.content.Intent
import android.os.Bundle
import com.hc.acoustics.R
import com.hc.acoustics.base.BaseActivity
import com.hc.acoustics.util.FormulaUtil
import com.yc.yclibrary.base.YcAppCompatActivity
import com.yc.yclibx.file.YcImgUtils
import kotlinx.android.synthetic.main.formula_button.*
import kotlinx.android.synthetic.main.type2_formula1_location_activity.*
import kotlinx.android.synthetic.main.type6_formula2_location_activity.*
import kotlinx.android.synthetic.main.type6_formula3_location_activity.*
import kotlinx.android.synthetic.main.type6_formula4_location_activity.*
import kotlinx.android.synthetic.main.type6_formula6_location_activity.*
import java.lang.NumberFormatException

/**
 *  系统设计 - 双低音音箱低音分频上限
 */
class Type6Formula6Activity : BaseActivity() {

    companion object {
        private const val KEY_TITLE = "key_title"
        @JvmStatic
        fun newInstance(activity: YcAppCompatActivity, title: String) {
            val intent = Intent(activity, Type6Formula6Activity::class.java)
            intent.putExtra(KEY_TITLE, title)
            activity.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.type6_formula6_location_activity
    }

    override fun initView(savedInstanceState: Bundle?) {
        setActionBar(intent.getStringExtra(KEY_TITLE))
        YcImgUtils.loadResIdImg(activity,R.drawable.formula_6_6,formula_6_6bgIv)
        formulaResetBtn.setOnClickListener {
            formula6_6_f1_1_TEV.reset()
            formula6_6_d1_1_TEV.reset()
            formula6_6_d1_2_TEV.reset()
            formula6_6_f1_2_TEV.reset()

            formula6_6_f2_1_TEV.reset()
            formula6_6_d2_1_TEV.reset()
            formula6_6_d2_2_TEV.reset()
            formula6_6_f2_2_TEV.reset()


        }
        formulaOkBtn.setOnClickListener {
            try {
                val result1D1 = FormulaUtil.formula6_6_1(formula6_6_f1_1_TEV.getDouble(), 3.0)
                val result1F1 = FormulaUtil.formula6_6_2(formula6_6_d1_2_TEV.getDouble(), 3.0)
                val result2D1 = FormulaUtil.formula6_6_1(formula6_6_f2_1_TEV.getDouble(), 2.0)
                val result2F1 = FormulaUtil.formula6_6_2(formula6_6_d2_2_TEV.getDouble(), 2.0)

                formula6_6_d1_1_TEV.setText(result1D1)
                formula6_6_f1_2_TEV.setText(result1F1)
                formula6_6_d2_1_TEV.setText(result2D1)
                formula6_6_f2_2_TEV.setText(result2F1)

            } catch (e: NumberFormatException) {
                formula6_6_d1_1_TEV.setText("Infinity")
                formula6_6_f1_2_TEV.setText("Infinity")
                formula6_6_d2_1_TEV.setText("Infinity")
                formula6_6_f2_2_TEV.setText("Infinity")
            }
        }
    }
}